package com.exam.student.mapper;

import com.exam.entity.*;
import com.exam.entity.dto.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 学生登录
     * @param login
     * @return
     */
    @Select("select * from student where studentId = #{username} and pwd = #{password}")
    StudentDto selectStudent(Login login);

    /**
     * 教师登录
     * @param login
     * @return
     */
    @Select("select * from teacher where teacherId = #{username} and pwd = #{password}")
    TeacherDto selectTeacher(Login login);

    /**
     * 管理员登录
     * @param login
     * @return
     */
    @Select("select * from admin where adminId = #{username} and pwd = #{password}")
    AdminDto selectAdmin(Login login);

    /**
     * 教师注册
     * @param registerDto
     * @return
     */
    int registerTeacher(RegisterDto registerDto);

    /**
     * 学生注册
     * @param registerDto
     * @return
     */
    int registerStudent(RegisterDto registerDto);

    /**
     * 根据id来查找学生信息
     * @param studentId
     * @return
     */
    Student findStudentById(Long studentId);

    /**
     * 根据id来查找教师信息
     * @param teacherId
     * @return
     */
    Teacher findTeacherById(Long teacherId);

    /**
     * 学生找回密码
     * @param forgotDto
     * @return
     */
    @Select("SELECT * FROM `student` where studentId = #{studentName} and tel = #{tel}")
    Student forgotStudentPwd(ForgotDto forgotDto);

    /**
     * 教师找回密码
     * @param forgotDto
     * @return
     */
    @Select("SELECT * FROM teacher where teacherId = #{teacherName} and tel = #{tel}")
    Teacher forgotTeacherPwd(ForgotDto forgotDto);

    @Select("select * from avatars where user_id = #{userId}")
    List<Avatar> findByIdAvatars(Long userId);

    @Delete("delete from avatars where avatar_path = #{filePath}")
    int deleteAvatar(String filePath);

}
